use crate::commands::{Opts, SubCommand};
use crate::storage::Storage;
use anyhow::Result;

pub mod error;
pub mod storage;
pub mod commands;

pub trait ExecuteCommand {
    fn execute_command(&self, storage: &impl Storage) -> Result<()>;
}

impl ExecuteCommand for Opts {
    fn execute_command(&self, storage: &impl Storage) -> Result<()> {
        self.subcmd.execute_command(storage)
    }
}

impl ExecuteCommand for SubCommand {
    fn execute_command(&self, storage: &impl Storage) -> Result<()> {
        match self {
            SubCommand::Add(add) => add.execute_command(storage),
            SubCommand::Cp(copy) => copy.execute_command(storage),
            SubCommand::Delete(delete) => delete.execute_command(storage),
            SubCommand::Edit(edit) => edit.execute_command(storage),
            SubCommand::List(list) => list.execute_command(storage),
            SubCommand::Delay(delay) => delay.execute_command(storage),
            SubCommand::Id(id) => id.execute_command(storage),
            SubCommand::C(complete) => complete.execute_command(storage),
            SubCommand::P(un_complete) => un_complete.execute_command(storage),
            SubCommand::Clear(clear) => clear.execute_command(storage),
        }
    }
}